/*
 * @Author: your name
 * @Date: 2020-12-27 11:23:17
 * @LastEditTime: 2021-01-27 23:29:40
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \6_bldc\include\bsp\stm32g474\stm32_gpio.h
 */
#ifndef __STM32_GPIO_H__
#define __STM32_GPIO_H__

#include "type.h"
#include "stm32regs.h"
#define PIN0 0
#define PIN1 1
#define PIN2 2
#define PIN3 3
#define PIN4 4
#define PIN5 5
#define PIN6 6
#define PIN7 7
#define PIN8 8
#define PIN9 9
#define PIN10 10
#define PIN11 11
#define PIN12 12
#define PIN13 13
#define PIN14 14
#define PIN15 15

#define GPIO_A 0
#define GPIO_B 1
#define GPIO_C 2
#define GPIO_D 3
#define GPIO_E 4
#define GPIO_F 5
#define GPIO_G 6
#define GPIO_H 7
#define GPIO_I 8

#define FTIR 1 //下降沿触发
#define RTIR 2 //上升沿触发

//mode
#define GPIO_MODE_INPUT (0x00000000U)          /*!< Select input mode */
#define GPIO_MODE_OUTPUT GPIO_MODER_MODE0_0    /*!< Select output mode */
#define GPIO_MODE_ALTERNATE GPIO_MODER_MODE0_1 /*!< Select alternate function mode */
#define GPIO_MODE_ANALOG GPIO_MODER_MODE0      /*!< Select analog mode */
//speed
#define GPIO_SPEED_FREQ_LOW (0x00000000U)              /*!< Select I/O low output speed    */
#define GPIO_SPEED_FREQ_MEDIUM GPIO_OSPEEDR_OSPEED0_0  /*!< Select I/O medium output speed */
#define GPIO_SPEED_FREQ_HIGH GPIO_OSPEEDR_OSPEED0_1    /*!< Select I/O fast output speed   */
#define GPIO_SPEED_FREQ_VERY_HIGH GPIO_OSPEEDR_OSPEED0 /*!< Select I/O high output speed   */
//pull 上下拉
#define GPIO_PULL_NO (0x00000000U)        /*!< Select I/O no pull */
#define GPIO_PULL_UP GPIO_PUPDR_PUPD0_0   /*!< Select I/O pull up */
#define GPIO_PULL_DOWN GPIO_PUPDR_PUPD0_1 /*!< Select I/O pull down */
//output type   输出方式
#define GPIO_OUTPUT_PUSHPULL (0x00000000U)    /*!< Select push-pull as output type 推挽输出  */
#define GPIO_OUTPUT_OPENDRAIN GPIO_OTYPER_OT0 /*!< Select open-drain as output type 开漏输出*/

void MY_NVIC_SetVectorTable(u32 NVIC_VectTab, u32 Offset);
void MY_NVIC_SetVectorTable(u32 NVIC_VectTab, u32 Offset);
void GPIO_Config(GPIO_TypeDef *GPIOx, uint32_t pin, uint32_t mode, uint32_t otype, uint32_t speed, uint32_t pupd);
void MY_NVIC_Init(u8 NVIC_PreemptionPriority, u8 NVIC_SubPriority, u8 NVIC_Channel, u8 NVIC_Group);
void GPIO_Set(GPIO_TypeDef *GPIOx, uint32_t pin, u8 status);
void GPIO_AF_Set(GPIO_TypeDef *GPIOx, u8 BITx, u8 AFx);
void GPIO_EnablePort(GPIO_TypeDef *GPIOx);

#endif